<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title th:text="${webLink.id != null ? '编辑网站链接' : '添加网站链接'} + ' - 控制面板'">网站链接管理 - 控制面板</title>
    <link rel="stylesheet" href="/css/style.css">
    <style>
        .form-control {
            display: block;
            width: 100%;
            padding: 10px 15px;
            font-size: 16px;
            line-height: 1.5;
            color: rgba(200, 230, 255, 0.9);
            background: linear-gradient(145deg, rgba(10, 20, 40, 0.8), rgba(20, 40, 80, 0.8));
            border: 1px solid rgba(100, 150, 200, 0.3);
            border-radius: 8px;
            transition: all 0.3s ease;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2),
                        inset 0 1px 2px rgba(255, 255, 255, 0.1);
            margin-bottom: 15px;
        }
        
        .form-control:focus {
            outline: none;
            border-color: rgba(0, 170, 255, 0.8);
            box-shadow: 0 0 15px rgba(0, 150, 255, 0.3),
                        inset 0 1px 2px rgba(255, 255, 255, 0.2);
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: rgba(200, 230, 255, 0.9);
        }
        
        .form-hint {
            font-size: 12px;
            color: rgba(180, 210, 240, 0.7);
            margin-top: 5px;
        }
        
        .form-container {
            background-color: rgba(30, 30, 30, 0.7);
            backdrop-filter: blur(10px);
            border-radius: 10px;
            padding: 25px;
            border: 1px solid rgba(100, 150, 200, 0.3);
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
        }
        
        .form-actions {
            margin-top: 25px;
            display: flex;
            gap: 10px;
        }
        
        .btn {
            display: inline-block;
            padding: 8px 16px;
            background: linear-gradient(145deg, rgba(0, 120, 210, 0.8), rgba(0, 80, 160, 0.8));
            color: white;
            text-decoration: none;
            border-radius: 8px;
            border: none;
            cursor: pointer;
            font-size: 14px;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
        }
        
        .btn:hover {
            background: linear-gradient(145deg, rgba(0, 140, 230, 0.9), rgba(0, 100, 180, 0.9));
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
        }
        
        .form-actions .btn {
            padding: 10px 20px;
            font-size: 16px;
            font-weight: 500;
            display: inline-flex;
            align-items: center;
            justify-content: center;
        }
        
        .form-actions .btn[type="submit"] {
            background: linear-gradient(145deg, rgba(0, 180, 50, 0.8), rgba(0, 150, 30, 0.8));
        }
        
        .form-actions .btn[type="submit"]:hover {
            background: linear-gradient(145deg, rgba(0, 200, 60, 0.9), rgba(0, 170, 40, 0.9));
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
        }
        
        .form-actions .btn[type="submit"]:before {
            content: '💾';
            margin-right: 8px;
        }
        
        .form-actions .btn-secondary:before {
            content: '↩';
            margin-right: 8px;
        }
        
        .btn-secondary {
            background: linear-gradient(145deg, rgba(80, 120, 160, 0.8), rgba(60, 100, 140, 0.8));
        }
        
        .btn-secondary:hover {
            background: linear-gradient(145deg, rgba(100, 140, 180, 0.9), rgba(80, 120, 160, 0.9));
        }
        
        .alert {
            padding: 15px;
            margin-bottom: 20px;
            border-radius: 8px;
            backdrop-filter: blur(10px);
        }
        
        .alert-success {
            background-color: rgba(40, 180, 80, 0.2);
            color: #2ecc71;
            border: 1px solid rgba(46, 204, 113, 0.3);
        }
        
        .alert-danger {
            background-color: rgba(180, 40, 40, 0.2);
            color: #e74c3c;
            border: 1px solid rgba(231, 76, 60, 0.3);
        }
        
        .icon-selector {
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
            margin-top: 10px;
        }
        
        .icon-option {
            width: 40px;
            height: 40px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 20px;
            background: rgba(40, 60, 100, 0.4);
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.3s ease;
        }
        
        .icon-option:hover, .icon-option.selected {
            background: rgba(0, 120, 210, 0.4);
            transform: translateY(-2px);
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
        }
    </style>
</head>
<body>
    <div class="dashboard-container">
        <div class="sidebar">
            <div class="sidebar-header">
                <h2>控制面板</h2>
            </div>
            <ul class="sidebar-menu">
                <li><a href="/dashboard">主页</a></li>
                <li><a href="/dashboard/profile">个人信息</a></li>
                <li><a href="/dashboard/change-password">修改密码</a></li>
                <li><a href="/dashboard/documents">文档管理</a></li>
                <li><a href="/dashboard/categories">分类管理</a></li>
                <li class="active"><a href="/dashboard/weblinks">网站链接</a></li>
                <li><a href="/dashboard/users">用户管理</a></li>
                <li><a href="/danmaku-display">弹幕墙</a></li>
                <li><a href="/" target="_blank">访问首页</a></li>
                <li><a href="/logout">退出登录</a></li>
            </ul>
        </div>
        
        <div class="main-content">
            <div class="dashboard-header">
                <div class="dashboard-title">
                    <h1 th:text="${webLink.id != null ? '编辑网站链接' : '添加网站链接'}">网站链接表单</h1>
                </div>
                <div>
                    <a href="/dashboard/weblinks" class="btn btn-secondary">返回列表</a>
                </div>
            </div>
            
            <!-- 成功/错误消息 -->
            <div th:if="${successMessage != null}" class="alert alert-success" th:text="${successMessage}"></div>
            <div th:if="${errorMessage != null}" class="alert alert-danger" th:text="${errorMessage}"></div>
            
            <!-- 网站链接表单 -->
            <div class="form-container">
                <form th:action="@{/dashboard/weblinks}" th:object="${webLink}" method="post">
                    <input type="hidden" th:field="*{id}">
                    
                    <div class="form-group">
                        <label for="title">标题</label>
                        <input type="text" id="title" th:field="*{title}" required placeholder="请输入网站标题" class="form-control">
                        <div class="form-hint">输入一个简短易记的网站标题</div>
                    </div>
                    
                    <div class="form-group">
                        <label for="url">URL</label>
                        <input type="url" id="url" th:field="*{url}" required placeholder="https://" class="form-control">
                        <div class="form-hint">请输入完整的网址，包括 http:// 或 https://</div>
                    </div>
                    
                    <div class="form-group">
                        <label for="description">描述</label>
                        <textarea id="description" th:field="*{description}" placeholder="请输入网站描述..." class="form-control"></textarea>
                        <div class="form-hint">简要描述该网站的内容和用途</div>
                    </div>
                    
                    <div class="form-group">
                        <label for="icon">图标</label>
                        <input type="text" id="icon" th:field="*{icon}" class="form-control" maxlength="2">
                        <div class="form-hint">选择一个表示该网站的图标</div>
                        <div class="icon-selector">
                            <div class="icon-option" data-icon="🔗">🔗</div>
                            <div class="icon-option" data-icon="🌐">🌐</div>
                            <div class="icon-option" data-icon="📱">📱</div>
                            <div class="icon-option" data-icon="💻">💻</div>
                            <div class="icon-option" data-icon="📚">📚</div>
                            <div class="icon-option" data-icon="🎮">🎮</div>
                            <div class="icon-option" data-icon="🎬">🎬</div>
                            <div class="icon-option" data-icon="🎵">🎵</div>
                            <div class="icon-option" data-icon="📝">📝</div>
                            <div class="icon-option" data-icon="📊">📊</div>
                            <div class="icon-option" data-icon="🛒">🛒</div>
                            <div class="icon-option" data-icon="💼">💼</div>
                        </div>
                    </div>
                    
                    <div class="form-group">
                        <label for="displayOrder">显示顺序</label>
                        <input type="number" id="displayOrder" th:field="*{displayOrder}" class="form-control">
                        <div class="form-hint">数字越小排序越靠前，默认为0</div>
                    </div>
                    
                    <!-- 添加网站链接分类选择 -->
                    <div class="form-group">
                        <label for="categoryId">分类</label>
                        <select class="form-control" id="categoryId" name="categoryId">
                            <option value="">-- 选择分类 --</option>
                            <option th:each="category : ${categories}" 
                                    th:value="${category.id}" 
                                    th:text="${category.name}"
                                    th:selected="${webLink.category != null && webLink.category.id == category.id}">
                                分类名称
                            </option>
                        </select>
                        <div class="form-hint">选择一个网站链接分类，可以留空</div>
                    </div>
                    
                    <div class="form-group">
                        <label>
                            <input type="checkbox" th:field="*{active}">
                            激活
                        </label>
                        <div class="form-hint">激活状态的链接才会显示在前台页面</div>
                    </div>
                    
                    <div class="form-actions">
                        <button type="submit" class="btn">保存网站链接</button>
                        <a href="/dashboard/weblinks" class="btn btn-secondary">取消</a>
                    </div>
                </form>
            </div>
        </div>
    </div>
    
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 图标选择器
            const iconOptions = document.querySelectorAll('.icon-option');
            const iconInput = document.getElementById('icon');
            
            // 初始选中当前图标
            iconOptions.forEach(option => {
                if (option.dataset.icon === iconInput.value) {
                    option.classList.add('selected');
                }
                
                option.addEventListener('click', function() {
                    // 移除所有选中状态
                    iconOptions.forEach(opt => opt.classList.remove('selected'));
                    // 添加当前选中状态
                    this.classList.add('selected');
                    // 设置输入框值
                    iconInput.value = this.dataset.icon;
                });
            });
        });
    </script>
</body>
</html> 